import 'package:app_router_demo/providers/auth_provider.dart';
import 'package:app_router_demo/providers/home_provider.dart';
import 'package:app_router_demo/providers/home_tab_provider.dart';
import 'package:app_router_demo/services/http_service.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'config/app_router.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // 在应用启动时初始化 HttpService
  await HttpService().initialize();

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    final appRouter = AppRouter(authGuard: AuthGuard());

    return MultiProvider(
      providers: [ChangeNotifierProvider(create: (_) => AuthProvider())],
      child: Builder(
        builder: (context) {
          return MaterialApp.router(
            debugShowCheckedModeBanner: false,
            routerDelegate: appRouter.delegate(),
            routeInformationParser: appRouter.defaultRouteParser(),
            routeInformationProvider: appRouter.routeInfoProvider(),
            builder: (context, child) {
              // 返回不包含HeroController的widget树
              return child!;
            },
          );
        },
      ),
    );
  }
}
